#include "PluginFactory.h"
#include "IConverter.h"

namespace PluginSystem
{


PluginFactory::PluginFactory(void)
{
	this->Register("convertor",&CreateConvertor);
}

PluginFactory::~PluginFactory(void)
{}


bool PluginFactory::Register(std::string pluginName,CreatePluging createPluginfunc)
{
	if(pluginName.empty() || createPluginfunc == NULL)
		return false;

	std::pair<std::map<std::string,CreatePluging>::iterator,bool> _ret;

	_ret = myObjectMap.insert( std::pair<std::string,CreatePluging>(pluginName,createPluginfunc) );
	
	return _ret.second;
}

IPlugin *PluginFactory::Create(std::string pluginName, std::string pluginPath)
{
	ObjectMap::const_iterator _iter = myObjectMap.find(pluginName);

	if(_iter == myObjectMap.end())
		return NULL;
	
	//ak objekt je registrovany tak vytvorime instanciu
	return (_iter->second)(pluginPath.c_str());
}

}//end of PluginSystem
